package com.example.demo01

import android.os.Bundle
import android.widget.Button
import android.widget.TextView
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat

class PageTwoActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_page_two)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }
        // 1. 接收传递的数据
        val name = intent.getStringExtra("user_name")
        val age = intent.getIntExtra("user_age", 0)
        findViewById<TextView>(R.id.pageTwo).text = "上个页面传递的数据: \n 姓名: $name, 年龄: $age"

        // 2. 获取按钮
        val btn = findViewById<Button>(R.id.btn_back)
        btn.setOnClickListener {
            finish()
        }
    }
}